package cm.example.shoppingplatformspringboot.utils;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 支付宝配置类
 * 用于配置支付宝客户端所需的参数
 */
@Configuration
public class AlipayConfig {
    /**
     * 支付宝网关
     */
    private static final String URL = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
    /**
     * 应用ID
     * 在支付宝开放平台创建应用后获取
     */
    private static final String APP_ID = "2021000148670095";

    /**
     * 商户私钥
     * 使用支付宝开放平台提供的工具生成
     * 注意：需要妥善保管，不要泄露
     */
    private static final String PRIVATE_KEY = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCS/xcn8T5rWmXp9ojBKIduwQnPZGXHSVnG23M/DDUHFI0VhbBeIq1ACINGGBUKT54gFDyz+6XxlRWA72/3whbbAPiI43s+VlrtD64rTIe0R/GjcsIUEaYd+c2fbQpckDev10IWIjfoiTbbWyGFknP/OWNVGKEaiVh2e0XLtan3mkiHHj489FkBC7+2RjPglbVwWKlRvN+DX+XkZClcthGuJ3QOQKLBqGOGbqTtlW3TBUTp7QbHBRHM5ekWGdfxME98b2jTRs3ZpgVzJPfZaEwbzfJkk4WR2M+GXOUsSQHnLdwe+oTs0SeK07p8OSVuEmDRNXTBFnoaRKePFz7VGLnBAgMBAAECggEAbAi61gpBm9i2ajtcysmkr8uEED5zZwILz1Dd5IpuNqPuBNFai/Tka9lV0aBFZmyZhG4bJxReI600Pqy7F9Y3wgF2p/S4UVpaPTx2/y+h1OfDOiNPbDyEYCeF7hPPt7PumXeVBHtlp6ug+5qAipDWW8+rp5EQZlZnA70Z0NvU7ToDbV8e455MuxRRkxHiaS14f7/0MUodVLqoGLnU1JqlrrXfS1fjIHGcCxNbO9ea1hyuX53Hkx0J401HhgboU7ApJlSUa1G/K76gb28dU+st/yf21iWfngeSwtyvysmYga5daHMwD0c3sVZTEut1KIe2iscD3tPTuclfh5ApqFsOgQKBgQDMEpgT4CkQ/vzboLE8l6Wl457MC6FfIF482NsAYS7EvuHiQrwtkCEFysqUMWphNtfBHx95pCWcXZbUURGfhlNJbwaA8HdkbaT/VTw19pBeppmZIATF1+ulV+dcrnHnPFue5MK7q7N8YXUgB8djzoidmCfn5zzY6fzu2xTUkNQAOQKBgQC4ZoWGu4ANNOqr4Gn7O8y/+nd91Pt7HtZDwYfgUG6uHd1wXjxXjje2s55VjqrvHRQeDUKiJZSLYj0R1ujJLtVt75K1kIXyKDUhd54L3WCC/KakN/rgqNk1TwV9kRraMKsaza70juCjHJ/LWz+oPTI9qoeOir506A4D78h0Ud71yQKBgDNQLZs5zzmt1CjphAdnXkiTLpfCCOahffCw2oiC5z6jfKrm+ug+CH+rWTrgHg6puqCd0c1FYAusYMOsStEg9opNd4YucOb4xvdJGGW9RNn37EFbkreormEZ9FwSpSNuwt72SJzl9LC+1LOkIRfQk/uEiew+8cbdNzNcNSWp8RTJAoGAaxG0NEAIoSJ5pCTgxKy7PTlMSnbxMlL8bEkiASASs+zJV+aPuPLt7Jqss9br73z94lkmuImDj88R0JrtfWtBJ900XVI2RB4Og4k17oOy9zuF8tJCTFIeFLL2aCtp4QjjQOPu0zdmva7wJZ6s/p3R3zZ2EVEEN1NKWATRaqDjCekCgYA0v+RXrk5MPbcNTLn3l5zBufRQVQgrTnqgiMWt9la0zcUmvNgg1AYd8jfOE76W2hUuqx8mBRBpIiMo120K4ja6Y3S9dCHZCQfw3sqGVuI9NNIB3cafvsWpbYeTSokaOwE4NStcGhJGq7NPo3Q32lwMNGTMsrkgdDa+UgJKAN+GXw==";

    /**
     * 支付宝公钥
     * 在支付宝开放平台获取
     * 用于验证支付宝的异步通知
     */
    public static final String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiTnsr42yGPwtvskpimvViULvTPQkIwf+PAhMCzk6PONsEef81ChtJ5ynuAJLJxKSjKiJp6EphqALeNhWiekqdT0i4oB5C+k0V+YUH1Y9loPDXFI14dC9mV56PC+VMAERrTNa5vXVbdDRIQV8neY7xVGDCnnBBal9QnP4W7zfDIaOuSQVlh799ct/XS0JBnIcHXhIz9wYRB68M4RzZlwQ+DjVtbD5JgRGYbf/k8qTMexy7M3D/wWOACCj7iUmu3hwJaW01W+rVHojOy4FUsaqFIF6JrLEMnBVVS01qq8wiUTwDThTBF7crWBxiLs60TB+DOk2z921958YsY+1LZBFiwIDAQAB";
    /**
     * 异步通知地址
     * 支付宝服务器主动通知商户服务器里指定的页面http/https路径
     * 建议使用https协议
     */
    public static final String NOTIFY_URL = "http://y786ca66.natappfree.cc/alipay/notify";
    /**
     * 同步返回地址
     * 支付完成后，用户从支付宝页面跳转回商户页面的地址
     */
    public static final String RETURN_URL = "http://localhost:5173/paySuccess";

    /**
     * 创建支付宝客户端
     *
     * @return AlipayClient实例
     */
    @Bean
    public AlipayClient alipayClient() {
        return new DefaultAlipayClient(
                URL, // 支付宝网关
                APP_ID, // 应用ID
                PRIVATE_KEY,  // 商户私钥
                "json", // 请求格式
                "UTF-8", // 编码格式
                ALIPAY_PUBLIC_KEY, // 支付宝公钥
                "RSA2" // 签名方式
        );
    }
}